home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PACKET / CBBS60SO.ZIP / MBINIT.C < prev    next >
Text File  |  1988-11-12  |  12KB  |  582 lines

  1.  
  2. /*
  3.  *  MBINIT.C - 9/19/88 - Read configuration file.
  4.  */
  5.  
  6. #include "mb.h"
  7.  
  8. #define minheap 8192
  9. #define minscr  4096
  10. #define maxscr  16384
  11.  
  12. /*
  13.  *  Read one line from the configuration file.
  14.  *  The first field is a number. Return it.
  15.  */
  16.  
  17. rdnumb()
  18. {
  19.   fgets (port->line, linelen, port->fl);
  20.   parse ();
  21.   return atoi (port->fld[0]);
  22. }
  23.  
  24. /*
  25.  *  Read one line from the configuration file.
  26.  *  The first field is a YES / NO keyword.
  27.  *  Return true if Y, false if N.
  28.  */
  29.  
  30. kw()
  31. {
  32.   fgets(port->line, linelen, port->fl);
  33.   parse();
  34.   return(*port->fld[0] is 'Y');
  35. }
  36.  
  37. /*
  38.  *  Read one line from the configuration file.
  39.  *  The first field is a letter.
  40.  *  Return the control character corresponding to that letter.
  41.  */
  42.  
  43. char cchr()
  44. {
  45.   fgets (port->line, linelen, port->fl);
  46.   return (*port->line - 64);
  47. }
  48.  
  49. /*
  50.  *  Read one line from the configuration file.
  51.  *  Squirrel it away in allocated memory.
  52.  *  Return a pointer to it.
  53.  */
  54.  
  55. char *rdstr()
  56. {
  57.   fgets (port->line, linelen, port->fl);
  58.   return strdup(port->line);
  59. }
  60.  
  61. /*
  62.  *  Read a line from the configuration file.
  63.  *  Remove the new line at end.
  64.  *  Squirrel it away in allocated memory.
  65.  *  Return a pointer to it.
  66.  */
  67.  
  68. char *rdstrnl()
  69. {
  70.   fgets (port->line, linelen, port->fl);
  71.   remnl(port->line);
  72.   return strdup(port->line);
  73. }
  74.  
  75. /*
  76.  *  Read multiple lines from the configuration file, until "*** EOF".
  77.  *  Squirrel them away in allocated memory in MLM structure.
  78.  *  Return a pointer to the structure.
  79.  */
  80.  
  81. MLM *rdmstr()
  82. {
  83.   register MLM *h, *m, *t;
  84.  
  85.   h = NULL;
  86.   fgets (port->line, linelen, port->fl);
  87.   while (!iseof(port->line))
  88.   {
  89.     m = (MLM *) malloc(sizeof(MLM));
  90.     if (h is NULL) h = m; else t->next = m;
  91.     m->next = NULL;
  92.     t = m;
  93.     m->text = strdup(port->line);
  94.     fgets(port->line, linelen, port->fl);
  95.   }
  96.   return h;
  97. }
  98.  
  99. /*
  100.  *  Read multiple lines from the configuration file, until "*** EOF".
  101.  *  Build the message hold list.
  102.  */
  103.  
  104. rdhold()
  105. {
  106.   register HOLD *hp;
  107.  
  108.   hold = NULL;
  109.   fgets (port->line, linelen, port->fl);
  110.   while (!iseof(port->line))
  111.   {
  112.     hp = (HOLD *)malloc(sizeof(HOLD));
  113.     hp->next = hold; hold = hp;
  114.     parse();
  115.     pcall(hp->call, port->fld[0]);
  116.  
  117.     fgets (port->line, linelen, port->fl);
  118.   }
  119. }
  120.  
  121. /*
  122.  *  Read multiple lines from the configuration file, until "*** EOF".
  123.  *  Build the @ BBS translation list.
  124.  */
  125.  
  126. rdxbbs()
  127. {
  128.   register XBBS *xp;
  129.  
  130.   xbbs = NULL;
  131.   fgets (port->line, linelen, port->fl);
  132.   while (!iseof(port->line))
  133.   {
  134.     xp = (XBBS *)malloc(sizeof(XBBS));
  135.     xp->next = xbbs; xbbs = xp;
  136.     parse();
  137.     pcall(xp->from, port->fld[0]);
  138.  
  139.     if (port->flds is 1) fill(xp->to, ' ', ln_call);
  140.     else pcall(xp->to, port->fld[1]);
  141.  
  142.     fgets (port->line, linelen, port->fl);
  143.   }
  144. }
  145.  
  146. /*
  147.  *  Read the directory path section of the configuration file.
  148.  */
  149.  
  150. rdpaths()
  151. {
  152.   register DIRPATH *p, *path;
  153.   register char *st;
  154.  
  155.   dphd = NULL;
  156.   fgets(port->line, linelen, port->fl);
  157.   while (!iseof(port->line))
  158.   {
  159.     path = (DIRPATH *) malloc(sizeof(DIRPATH));
  160.     path->next = NULL;
  161.     if (dphd is NULL) dphd = path; else p->next = path;
  162.     p = path;
  163.  
  164.     parse();
  165.     st = port->fld[0];
  166.     path->flags = 0;
  167.     path->id = *st++;
  168.     while(*st)
  169.     {
  170.       switch(*st)
  171.       {
  172.         case 'D': path->flags setbit dp_dnload; break;
  173.         case 'U': path->flags setbit dp_upload; break;
  174.         default : ;
  175.       }
  176.       st++;
  177.     }
  178.     path->path = rdstrnl();
  179.     path->name = rdstrnl();
  180.  
  181.     fgets(port->line, linelen, port->fl);
  182.   }
  183. }
  184.  
  185. /*
  186.  *  Read the port definition section of the configuration file.
  187.  */
  188.  
  189. rdports()
  190. {
  191.   register PORTS *p, *pt;
  192.   register char *st;
  193.   short first = true;
  194.   byte mask = 0x00000001;
  195.   byte pflg;
  196.   window = 0;
  197.  
  198.   pt = porthd;
  199.   fgets (port->line, linelen, port->fl);
  200.   while (!iseof(port->line))
  201.   {
  202.     parse();
  203.  
  204.     if (!first)
  205.     {
  206.       pt = (PORTS *) malloc(sizeof(PORTS));
  207.       pt->cmd  = (char *)malloc(cmdlen);
  208.       pt->line = (char *)malloc(linelen);
  209.       p->next = pt;
  210.     }
  211.  
  212.     first = false;
  213.     p = pt;
  214.     pt->next = NULL;
  215.  
  216.     p->mode = idle;
  217.     p->lport = NULL;
  218.  
  219.     pt->user = (USER *)malloc(sizeof(USER));
  220.     pt->user->rn = 0;
  221.  
  222.     pt->mmhs = (MSG_HDR *)malloc(sizeof(MSG_HDR));
  223.     pt->mmhs->rn = 0;
  224.  
  225.     pt->cmdcnt = 0;
  226.     pt->msg = NULL;
  227.  
  228.     st = port->fld[0];
  229.     pt->dev    = 0;
  230.     pt->priv   = 0;
  231.     pt->flags  = p_give | p_dotmr;
  232.     pt->ecmon  = false;
  233.     pt->eccmds = false;
  234.     pt->ecuser = false;
  235.     pt->tmode  = false;
  236.     pt->id     = *st++;
  237.     pt->idn    = (int)(pt->id - 'A');
  238.     if (pt->idn < 8) window setbit (mask << pt->idn);
  239.     while(*st)
  240.     {
  241.       switch(*st)
  242.       {
  243. /*
  244.  *  Device type.
  245.  */
  246.         case 'C': pt->dev = p_console; cport = pt; break;
  247.         case 'S': pt->dev = p_serial;  break;
  248.         case 'T': pt->dev = p_tnc;     break;
  249. /*
  250.  *  Device characteristics.
  251.  */
  252.         case 'E': pt->flags setbit p_echo;   break;
  253.         case 'L': pt->flags setbit p_lf;     break;
  254.         case '1': pt->ecmon  = true;         break;
  255.         case '2': pt->ecuser = true;         break;
  256.         case '3': pt->eccmds = true;         break;
  257.         case 'X': pt->tmode  = true;         break;
  258. /*
  259.  *  Port priveleges and permissions.
  260.  */
  261.         case 'B': pt->priv setbit p_bbs;     break;
  262.         case 'D': pt->priv setbit p_dnload;  break;
  263.         case 'G': pt->priv setbit p_gate;    break;
  264.         case 'I': pt->priv setbit p_ilcal;   break;
  265.         case 'M': pt->priv setbit p_mon;     break;
  266.         case 'R': pt->priv setbit p_sysop;   break;
  267.         case 'U': pt->priv setbit p_upload;  break;
  268.       }
  269.       st++;
  270.     }
  271.     pt->mode   = idle;
  272.     pt->ctime  = atoi(port->fld[1]);
  273.     pt->dtime  = atoi(port->fld[2]);
  274.     pt->mtime  = atoi(port->fld[3]);
  275.     pt->mcount = atoi(port->fld[4]);
  276.     pt->maxhrd = atoi(port->fld[5]);
  277.     pt->ndigi  = atoi(port->fld[6]);
  278.     pt->fwdmin = atoi(port->fld[7]);
  279.     pt->errmax = atoi(port->fld[8]);
  280.     pt->ftime  = atoi(port->fld[9]);
  281.  
  282.     pt->nhrd   = 0;
  283.     pt->heard  = (char *) malloc(13 * pt->maxhrd);
  284.     pt->name   = rdstrnl();
  285.  
  286.     pt->ec = pt->ecmon;
  287.  
  288.     fgets(port->line, linelen, port->fl);
  289.   }
  290.   pflg = getp_flag();
  291.   putp_flag (pflg setbit window);
  292.   printf ("Window %X  port flag %X\n", window, pflg);
  293.  
  294.   ioinit();
  295.  
  296. /*
  297.  *  Drain any garbage from the port.
  298.  */
  299.  
  300.   for (p = porthd; p isnt NULL; p = p->next)
  301.   {
  302.     ioport(p);
  303.     switch(p->dev)
  304.     {
  305.       case p_tnc    :
  306.         while(instat()) inchar();
  307.         p->mode = remote;
  308.         if (p->tmode) p->flags setbit p_trans;
  309.         distnc();
  310.         p->mode = idle;
  311.         break;
  312.  
  313.       case p_serial :
  314.       case p_console:
  315.         while(instat()) inchar();
  316.  
  317.       default       : ;
  318.     }
  319.   }
  320.  
  321.   ioport(porthd);
  322.   printf("\n");
  323. }
  324.  
  325. /*
  326.  *  Do the initialization. Called from mainline.
  327.  */
  328.  
  329. init(file)
  330. char *file;
  331. {
  332.   word avl;
  333.  
  334. /*
  335.  *  Set default system params.
  336.  */
  337.  
  338.   s_param = s_page;
  339.  
  340. /*
  341.  *  Need structure for parse, so allocate a port.
  342.  */
  343.  
  344.   porthd       = (PORTS *) malloc(sizeof(PORTS));
  345.   porthd->cmd  = (char *)  malloc(cmdlen);
  346.   porthd->line = (char *)  malloc(linelen);
  347.   ioport(porthd);
  348.  
  349. /*
  350.  *  Open the configuration file.
  351.  */
  352.  
  353.   if ((port->fl = fopen(file, "r")) is NULL)
  354.   {
  355.     printf("Cannot open %s\n", file); exit(1);
  356.   }
  357.  
  358. /*
  359.  *  Read the configuration file, set everything up.
  360.  */
  361.  
  362.   rdports();
  363.   rdpaths();
  364.   rdxbbs();
  365.   rdhold();
  366.   rdcnf();
  367.  
  368.   fclose(port->fl);
  369.  
  370.   ioport(cport);
  371.  
  372.   opnmon();
  373.   opnmsg();
  374.   opnusr();
  375.   opnbid();
  376.  
  377.   rduser(tcall, cport->user);
  378.  
  379. /*
  380.  *  If owners user record did not exist, make him one of the right kind.
  381.  */
  382.  
  383.   if (!cport->user->rn)
  384.   {
  385.     cport->user->options = u_bbs | u_sysop | u_local;
  386.     strncpy(cport->user->home_bbs, tcall, ln_call);
  387.     upduser(cport->user);
  388.   }
  389.  
  390.   opnlog();
  391.   log ('C','I',' ',nullstr);
  392.  
  393. /*
  394.  *  Grab a mess of memory.
  395.  *  16k max. Leave at least 8k for heap.
  396.  */
  397.  
  398.   avl = _memavl();
  399.   if ( (avl - minheap) > maxscr ) scrmax = maxscr;
  400.   else scrmax = avl - minheap;
  401.   if (scrmax < minscr)
  402.   {
  403.     printf("Too little memory available.\n");
  404.     exit(1);
  405.   }
  406.   tmp = (TMP *) malloc(scrmax);
  407.   printf("There is %u free space, %u will be used.\n", avl, scrmax + minheap);
  408.   dirmax = scrmax / sizeof(DIRENT);
  409.   seed();
  410.   dosinit();
  411.  
  412. /*
  413.  *  Set initial beacon text.
  414.  */
  415.  
  416.   setfwd();
  417.   clsmsg();
  418.   clsusr();
  419. }
  420.  
  421. seed()
  422. {
  423.   register short curmin;
  424.   curtim(); curmin=10 * (l_time[2]-'0') + (l_time[3]-'0');
  425.   srand(curmin);
  426. }
  427. /*
  428.  *  Read the rest of the configuration file,
  429.  *  after the port and path definitions.
  430.  */
  431.  
  432. rdcnf()
  433. {
  434.   register int i;
  435.  
  436. /*
  437.  *  Login message.
  438.  */
  439.  
  440.   motd = rdmstr();
  441.  
  442. /*
  443.  *  Prompts.
  444.  */
  445.  
  446.   bbmenu = rdstr();  /* Prompt for connected bbs */
  447.   symenu = rdstr();  /* Local and remote sysop prompt */
  448.   rmenus = rdstr();  /* User prompt */
  449.  
  450. /*
  451.  *  Who are we?
  452.  */
  453.  
  454.   fgets (port->line, linelen, port->fl);
  455.   pcall (tcall, port->line);
  456.  
  457. /*
  458.  *  Where are we?
  459.  */
  460.  
  461.   qth = rdstrnl();
  462.  
  463. /*
  464.  *  Who is our name server?
  465.  */
  466.  
  467.   fgets (port->line, cmdlen, port->fl);
  468.   pcall (wpcall, port->line);
  469.  
  470. /*
  471.  *  File names and directory paths used by MailBox.
  472.  */
  473.  
  474.   helpfile = rdstrnl();
  475.   infofile = rdstrnl();
  476.   fwdfile  = rdstrnl();
  477.   lgfile   = rdstrnl();
  478.   monfile  = rdstrnl();
  479.   mbfile   = rdstrnl();
  480.   mbbfile  = rdstrnl();
  481.   usfile   = rdstrnl();
  482.   usbfile  = rdstrnl();
  483.   msgdir   = rdstrnl();
  484.   bidfile  = rdstrnl();
  485.  
  486.   hrdfile  = rdstrnl();
  487.   hrdmax   = rdnumb();
  488.  
  489. /*
  490.  *  Automatic mail untangle at what hour?
  491.  *  NO or YES hh  Where hh is the untangle hour 0-23
  492.  */
  493.  
  494.   if (kw())
  495.   {
  496.   s_param setbit s_unt;
  497.   unt_hr = atoi(port->fld[1]);
  498.   }
  499.  
  500. /*
  501.  *  Give time slice back to DESQview?
  502.  */
  503.  
  504.   if (kw()) s_flag setbit s_dv;
  505.  
  506. /*
  507.  *  Prompt for user info?
  508.  */
  509.  
  510.   if (kw()) s_param setbit s_p_name;
  511.   if (kw()) s_param setbit s_p_home;
  512.   if (kw()) s_param setbit s_p_zip;
  513.  
  514. /*
  515.  *  Logging
  516.  */
  517.  
  518.   if (kw()) s_param setbit s_log_on;
  519.   if (kw()) s_param setbit s_log_gate;
  520.   if (kw()) s_param setbit s_log_file;
  521.   if (kw()) s_param setbit s_log_msg;
  522.   if (kw()) s_param setbit s_log_loc;
  523.  
  524. /*
  525.  *  Control characters.
  526.  */
  527.  
  528.   achar = cchr();
  529.   rchar = cchr();
  530.   tchar = cchr();
  531.   wchar = cchr();
  532.  
  533.   pausemsg = rdstr();
  534. /* Text for local display of user call. */
  535.   mumsg = rdstr();
  536. /* Text to send when get connect request. */
  537.   reqmsg = rdstr();
  538. /* Various "talk to the owner" texts. */
  539.   talkm1 = rdstr();
  540.   talkm2 = rdstr();
  541.   talkm3 = rdstr();
  542.   talkm4 = rdstr();
  543. /* GateWay Messages. */
  544.   for (i = 0; i < num_gm; i++) gm[i] = rdstr();
  545. /* MailBox messages. */
  546.   for (i = 0; i < num_mm; i++) mm[i] = rdstr();
  547. /* Max calls in unread mail list. */
  548.   ufwdm = rdnumb();
  549.   bfwdm = rdnumb();
  550. /* Kill regular message after forward? */
  551.   if (kw()) s_param setbit s_kill;
  552. /* Kill F message after forward? */
  553.   if (kw()) s_param setbit s_fkill;
  554. /* Generate service msg after KT? */
  555.   if (kw()) s_param setbit s_svc;
  556. /* Enable ET command? */
  557.   if (kw()) s_param setbit s_edtfc;
  558. /* How many days before a message becomes stale */
  559.   tstaleb = rdnumb();
  560.   tstalen = rdnumb();
  561.   tstaleu = rdnumb();
  562. /* Upload/download prompts. */
  563.   fm = rdstr();
  564. /* User file text. */
  565.   for (i = 0; i < num_um; i++) um[i] = rdstr();
  566.   remnl(um[0]);
  567. /* Error/status messages. */
  568.   mcant  = rdstr();
  569.   mfind  = rdstr();
  570.   mprot  = rdstr();
  571.   mexst  = rdstr();
  572.   mtime  = rdstr();
  573.   mwhat  = rdstr();
  574.   mdone  = rdstr();
  575.   mnport = rdstr();
  576.   mndir  = rdstr();
  577.   mnfile = rdstr();
  578.   mnmsg  = rdstr();
  579.   minuse = rdstr();
  580.   keylst = rdstr();
  581. }
  582.